package com.hanrui.android.activity.mine;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.blankj.utilcode.util.ToastUtils;
import com.hanrui.android.R;
import com.hanrui.android.library.base.ActionBarBaseActivity;
import com.hanrui.android.model.InvoiceListBean;
import com.hanrui.android.net.contract.mine.BillDetailContract;
import com.hanrui.android.net.presenter.mine.BillDetailPresenter;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 发票详情
 */
public class BillDetailActivity extends ActionBarBaseActivity<BillDetailPresenter> implements BillDetailContract.View {

    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.duty_Num)
    TextView dutyNum;
    @BindView(R.id.company_address)
    TextView companyAddress;
    @BindView(R.id.company_phone)
    TextView companyPhone;
    @BindView(R.id.bank_name)
    TextView bankName;
    @BindView(R.id.bank_num)
    TextView bankNum;
    @BindView(R.id.delet)
    TextView delet;
    @BindView(R.id.edit)
    TextView edit;

    InvoiceListBean invoiceListBean;

    String bizId;

    @Override
    protected void initInjector() {mActivityComponent.inject(this);}


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_billdetail);

        unbinder = ButterKnife.bind(this);

        mTitleBar.setTitle("发票信息");

        bizId = getIntent().getStringExtra("bizId");

    }



    @OnClick({ R.id.delet,R.id.edit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.delet:
                mPresenter.invoiceDelete(this,invoiceListBean.getId());
                break;
            case R.id.edit:
                AddBillActivity.start(BillDetailActivity.this,invoiceListBean);
                break;
        }
    }


    @Override
    protected void onResume() {
        super.onResume();
        mPresenter.invoiceBizDetail(this,bizId);
    }

    public static void start(Context context, String bizId){

        Intent intent = new Intent(context,BillDetailActivity.class);
        intent.putExtra("bizId",bizId);
        context.startActivity(intent);

    }

    @Override
    public void invoiceBizDetail(InvoiceListBean bean) {

        if (null != bean) {

            invoiceListBean = bean;
            name.setText(bean.getCompanyName());
            dutyNum.setText(bean.getDutyNo());
            companyAddress.setText(bean.getOfficeName());
            companyPhone.setText(bean.getPhone());
            bankName.setText(bean.getBankName());
            bankNum.setText(bean.getBankAccount());

        }


    }

    @Override
    public void invoiceDelete(int code) {
        if (code == 1) {

            ToastUtils.showShort("删除成功");
            onBackPressed();

        		}else {

            ToastUtils.showShort("删除失败");
        }


    }
}
